package com.power.mediators
{
	import com.greensock.TweenLite;
	import com.power.enum.NotificationTypes;
	import com.power.events.HouseFloorEvent;
	import com.power.interfaces.IViewMediator;
	import com.power.model.FloorVo;
	import com.power.model.Notification;
	import com.power.model.RoomVo;
	import com.power.views.HouseWindowView;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.effects.Tween;
	
	public class HouseWindowViewMediator implements IViewMediator
	{
		private var _houseView:HouseWindowView;
		
		public function HouseWindowViewMediator()
		{
			
		}
		
		public function initView(view:DisplayObject):void
		{
			_houseView = view as HouseWindowView;
		
		}
		
		public function changeHouseHandler(e:HouseFloorEvent):void
		{
			handleNotification(e.notification);
		}
		
		public function dispatchEvent(type:String, data:Object):void
		{
		}
		
		public function handleNotification(notification:Notification):void
		{
			var notifi:Notification = notification as Notification;
			var nofi_type:String = notifi.type;
			var nofi_body:Object = notifi.body;
			if(nofi_type==NotificationTypes.CHANGE_ROOM)
			{
				var roomVo:RoomVo = nofi_body.roomVo;
				changeRoom(roomVo);
			}else
			{
				var floorVo:FloorVo = nofi_body.floorVo;
				changeFloor(floorVo);
			}
			
		}
		
		public function hide():void
		{
			_houseView.visible = false;
		}
		
		public function show():void
		{
			_houseView.visible = true;
		}
		private function changeRoom(roomVo:RoomVo):void
		{
			_houseView.room.source = roomVo._image;
		}
		private function changeFloor(floorVo:FloorVo):void
		{
			addEffect(floorVo);
		}
		
		private function addEffect(floor:FloorVo):void
		{
			TweenLite.to(_houseView.floor,1,{alpha:0.1,onComplete:endFun,onCompleteParams:[floor]})
		}
		private function endFun(floor:FloorVo):void
		{
			TweenLite.to(_houseView.floor,1,{alpha:1})	
			_houseView.floor.source = floor._image;
		}
		//set floor house image
		public function setFloorImg(floorvos:Vector.<FloorVo>):void
		{
			//if(floorvos.length > 0){
				changeFloor(floorvos[0] as FloorVo)
			//}
		}
		//set rom house image
		public function setRoomImg(roomvos:Vector.<RoomVo>):void
		{
			changeRoom(roomvos[0] as RoomVo)
		}
	}
}